'##############
'Electricity Script
'##############

'Controls Bus Electicity and tells the systems
'if the busbar is active or not

'(c) 13.06.2009 Marcel Kuhnt

'Script Version: 1.0
'Omsi release: 1.0

'Needs:
'- engine

'Revision History:
'- Marcel Kuhnt		13.06.2009	File Created
'- Rüdiger Hülsmann	23.12.2010	L.L.elec_busbar_avail = 1 by init


'Attention:
'============
'All voltages are measured without units.
'1.0 means 100% of the normal voltage, 0.0 means no voltage.

'--------------------------------------------------------------



{macro:Elec_Init}
'At the beginning, battery has enough voltage:
	1.0 (S.L.elec_V_battery) (L.L.elec_busbar_avail)
{end}

{macro:Elec_Frame}

'If engine's RPM is high enough, generator will become active:

	(L.L.engine_n) (C.L.elec_generator_minRPM) > (S.L.elec_V_generator)

'Battery's voltage decrease while main busbar switch is on (but only to zero ;-) ):
	(L.L.elec_busbar_main_sw)
	{if}
		(L.L.elec_V_battery)
		(L.S.Timegap) (C.L.elec_battery_duration) / 
		- 0 max (S.L.elec_V_battery)
	{endif}

'But battery's voltage instantly grows up to the level of the generator voltage; value will be stored for further steps.

	(L.L.elec_V_battery) (L.L.elec_V_generator) max (S.L.elec_V_battery)

'If the battery voltage is above minimum and there is no electricity failure, the busbar becomes available

	(C.L.elec_busbar_Vmin) >= (L.L.elec_failure_general) ! &&
	{if}
		1 (S.L.elec_busbar_avail)
	{else}
		0 (S.L.elec_busbar_avail)
	{endif}

'If the battery or generator has voltage and if the switch is on and if there is no electricity failure,
'the main busbar will become active:

	(L.L.elec_busbar_avail)
	(L.L.elec_busbar_main_sw) &&
	(L.L.elec_failure_general) ! &&
	(S.L.elec_busbar_main)

{end}

